<%--                                                                       --%>
<%-- Copyright (c) 2004-2005 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>

<script language="JavaScript">

//
//
//
function selectJspPopup() {
  jspScriptPickerPopup('setSelectedJsp');
}

//
//
//
function setSelectedJsp(jspPath) {
  document.userTemplateDetailsForm.personalProfilePagePath.value = jspPath;
}

//
//
//
function doCancelAction(form) {
  var ok = true; // confirm('<bean-el:message key="confirmCancel" bundle="ep.messages"/>');
  if (ok && form != null) {
<c:if test="${userTemplateDetailsForm.map.id == 0}">
    form.action = '<c:url value="/ep/userTemplateList.do"/>';
</c:if>
<c:if test="${userTemplateDetailsForm.map.id != 0}">
    <c:url var="cancelUrl" value="/ep/userTemplateDetailsView.do">
      <c:param name="userTemplateId" value="${userTemplateDetailsForm.map.id}"/>
    </c:url>
    form.action = '<c:out value="${cancelUrl}"/>';
</c:if>
    form.submit();
  }
}

function doResetAction(myform) {
  var ok = true; // confirm('<bean-el:message key="confirmReset" bundle="ep.messages"/>');
  if (ok && myform != null) {
    myform.reset();
    doSpecifyMaxNumberOfTabs(myform);
    myform.maxPageNumber.value = myform.maxPageNumber.defaultValue;
  }
}

function checkNumberOnly(e) {
  var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
  if (charCode > 31 && (charCode < 48 || charCode > 57)) {
    return false;
  }
  else {
    return true;
  }
}

function trimTextFields(myform) {
  var theName = myform.name.value;
  myform.name.value = theName.stringTrim();
  var theDescription = myform.description.value;
  myform.description.value = theDescription.stringTrim();
  var thePersonalProfilePagePath = myform.personalProfilePagePath.value;
  myform.personalProfilePagePath.value = thePersonalProfilePagePath.stringTrim();
  var theFeedbackEmailAddress = myform.feedbackEmailAddress.value;
  myform.feedbackEmailAddress.value = theFeedbackEmailAddress.stringTrim();
}

function doValidation(myform) {
  trimTextFields(myform);
  <c:if test="${userTemplateDetailsForm.map.scriptOptional == false}">
	if (myform.personalProfilePagePath.value == null || myform.personalProfilePagePath.value == "")
	{
      alert('<bean-el:message key="error.specify" bundle="ep.messages"/> ' +
			'<bean-el:message key="ep.user.template.personal.profile.script" bundle="ep.messages"/>');
	  return false;
	}
  </c:if>
  if (validateUserTemplate(myform) == false) {
    return false;
  }
  var specifyMaxNumberOfTabs = myform.specifyMaxNumberOfTabs;
  var maxPageNumber = myform.maxPageNumber;
  if (specifyMaxNumberOfTabs.checked == true && maxPageNumber.value <= 0) {
    alert('<bean-el:message key="ep.user.template.details.error.invalidMaxTab" bundle="ep.messages"/>');
    myform.maxPageNumber.focus();
    return false;
  }
  var countRequired = <c:out value="${userTemplateDetailsForm.map.numberOfRequiredPageTypes}"/>;
  if (specifyMaxNumberOfTabs.checked == true && maxPageNumber.value < countRequired) {
    alert('<bean-el:message key="error.user.template.lessRequiredPageTypes" bundle="ep.messages" arg0="${userTemplateDetailsForm.map.numberOfRequiredPageTypes}"/>');
    myform.maxPageNumber.focus();
    return false;
  }
  var utid = <c:out value="${userTemplateDetailsForm.map.id}"/>;
  var nou = <c:out value="${userTemplateDetailsForm.map.numberOfUsers}"/>;
  if (utid > 0 && nou > 0 && myform.status[1].checked == true && myform.status[0].defaultChecked == true) {
    if (!confirm('<bean-el:message key="ep.user.template.confirm.offline" bundle="ep.messages"/>')) {
      return false;
    }
  }
  if (specifyMaxNumberOfTabs.checked == false) {
    maxPageNumber.value = 0;
  }
  return true;
}

function doSpecifyMaxNumberOfTabs(myform) {
  var smnot = myform.specifyMaxNumberOfTabs;
  var mpnl = document.getElementById('maxPageNumberLabel');
  var mpn = myform.maxPageNumber;
  if (smnot.checked == false) {
    mpnl.style.visibility = 'hidden';
    mpnl.style.display = 'none';
    mpn.style.visibility = 'hidden';
    mpn.style.display = 'none';
  }
  else {
    mpnl.style.visibility = 'visible';
    mpnl.style.display = '';
    mpn.style.visibility = 'visible';
    mpn.style.display = '';
    mpn.value = <c:out value="${userTemplateDetailsForm.map.numberOfRequiredPageTypes}"/>;
  }
  return true;
}

</script>

<%@include file="/ep/file/jspScriptPickerHelper.jsp" %>

<html-el:javascript formName="/ep/userTemplateSave" method="validateUserTemplate"/>
<html-el:form action="/ep/userTemplateSave.do" focus="name" onsubmit="return doValidation(userTemplateDetailsForm);">
<input type="hidden" name="userTemplateId" value="<c:out value='${param.userTemplateId}'/>"/>
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
<c:if test="${userTemplateDetailsForm.map.id == 0}">
        <bean-el:message key="ep.user.template.create.page.title" bundle="ep.messages"/>
</c:if>
<c:if test="${userTemplateDetailsForm.map.id != 0}">
		<bean-el:message key="ep.user.template.edit.page.title" arg0="${userTemplateDetailsForm.map.name}" bundle="ep.messages"/>
</c:if>
      </div>
      <div class="errorMessage"><html-el:errors bundle="ep.messages"/></div>
      <%@ include file="/mc/common/pagetab.jsp" %>

      <div class="pageSubtitle">
        <span class="left">
          <bean-el:message key="ep.user.template.information" bundle="ep.messages"/>
        </span>
      </div>

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="<bean-el:message key='ep.page.types' bundle="ep.messages"/>">
        <tr>
          <td class="label" width="30%">
            <bean-el:message key="ep.user.template.name" bundle="ep.messages"/>:*
          </td>
          <td class="labelField" width="70%">
  <html-el:text name="userTemplateDetailsForm" property="name" size="30" maxlength="80"/>
          </td>
        </tr>
        <tr>
          <td class="label" width="30%">
            <bean-el:message key="ep.user.template.description" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="70%">
            <html-el:textarea name="userTemplateDetailsForm" property="description" rows="4" cols="50"/>
          </td>
        </tr>
        <tr>
          <td class="label" width="30%">
            <bean-el:message key="ep.status" bundle="ep.messages"/>:
          </td>
           <td class="labelField" width="70%">
            <html-el:radio name="userTemplateDetailsForm" property="status" value="true">
               <bean-el:message key="ep.status.online" bundle="ep.messages"/>
            </html-el:radio>
            <html-el:radio name="userTemplateDetailsForm" property="status" value="false">
               <bean-el:message key="ep.status.offline" bundle="ep.messages"/>
            </html-el:radio>
          </td>
        </tr>
        <tr>
          <td class="label" width="30%">
			<c:choose>
			<c:when test="${userTemplateDetailsForm.map.scriptOptional}">
				<bean-el:message key="ep.user.template.personal.profile.script" bundle="ep.messages"/>:
            </c:when>
			<c:otherwise>
				<bean-el:message key="ep.user.template.personal.profile.script" bundle="ep.messages"/>:*
			</c:otherwise>
            </c:choose>
          </td>
          <td class="labelField" width="70%">
            <html-el:text name="userTemplateDetailsForm" property="personalProfilePagePath" size="30" maxlength="80"/>
            <input type="button" name="findScript" class="pageButton"
               onClick="selectJspPopup();"
               value="<bean-el:message key="button.browse" bundle="ep.messages"/>">
          </td>
        </tr>
        <tr>
          <td class="label" width="30%">
            <bean-el:message key="ep.user.template.feedback.email.address" bundle="ep.messages"/>:
          </td>
         <td class="labelField" width="70%">
            <html-el:text name="userTemplateDetailsForm" property="feedbackEmailAddress" size="30" maxlength="80"/>
          </td>
        </tr>
                <tr>
          <td class="label" width="30%">
            <bean-el:message key="ep.user.template.details.customization.rules" bundle="ep.messages"/>:
          </td>
          <td class="labelField" width="70%">
            <html-el:checkbox name="userTemplateDetailsForm" property="changeColorEnabled">
               <bean-el:message key="ep.user.template.details.allow.to.change.color" bundle="ep.messages"/>
            </html-el:checkbox>
          </td>
        </tr>
        <tr>
          <td class="label" width="30%">
            &nbsp;
          </td>
          <td class="labelField" width="70%">
            <html-el:checkbox name="userTemplateDetailsForm" property="homePageEnabled">
               <bean-el:message key="ep.user.template.details.allow.to.change.homepage" bundle="ep.messages"/>
            </html-el:checkbox>
          </td>
        </tr>
        <tr>
          <td class="label" width="30%">
            &nbsp;
          </td>
          <td class="labelField" width="70%">
            <html-el:checkbox name="userTemplateDetailsForm" property="specifyMaxNumberOfTabs" onclick="return doSpecifyMaxNumberOfTabs(this.form);">
               <bean-el:message key="ep.user.template.details.specify.max.number.of.tabs" bundle="ep.messages"/>
            </html-el:checkbox>
            &nbsp;&nbsp;
            <span id="maxPageNumberLabel">
            <bean-el:message key="ep.user.template.details.max.number.of.tabs" bundle="ep.messages"/>:
            </span>
            <html-el:text name="userTemplateDetailsForm" property="maxPageNumber" size="3" maxlength="3" onkeypress="return checkNumberOnly(event)"/>
          </td>
        </tr>
      </table>
      <div class="pageButtonWrap" align="right">
        <input type="button" name="actionReset" class="pageButton"
          value="<bean-el:message key="button.reset" bundle="ep.messages"/>"
          onclick="doResetAction(this.form)">
        &nbsp;&nbsp;
        <input type="button" name="actionCancel" class="pageButton"
          value="<bean-el:message key="button.cancel" bundle="ep.messages"/>"
          onclick="doCancelAction(this.form)">
        <input type="submit" name="actionSave" class="pageButton"
          value='<bean-el:message key="button.save" bundle="ep.messages"/>'>
      </div>
    </td>
  </tr>
</table>
<script language="Javascript1.2">
  var smnot = <c:out value="${userTemplateDetailsForm.map.specifyMaxNumberOfTabs}"/>;
  if (smnot != null && smnot == false) {
    var theform = document.forms['userTemplateDetailsForm'];
    var mpnl = document.getElementById('maxPageNumberLabel');
    mpnl.style.visibility = 'hidden';
    mpnl.style.display = 'none';
    theform.maxPageNumber.style.visibility = 'hidden';
    theform.maxPageNumber.style.display = 'none';
  }
</script>
</html-el:form>
